﻿using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;
using System.Linq;
namespace HelperPrototype.Reports {
    
    
    public partial class DS_DonDatHang {
        partial class DonDatHangDataTable
        {
        }
            string maPhieu;
            string maNcc;
            public void fillData(string maPhieu,string maNcc)
            {

                this.maPhieu = maPhieu;
                this.maNcc = maNcc;
                SqlConnection con = new SqlConnection(Properties.Settings.Default.myConnectionString);
                con.Open();

                string sql = "select PH.*,H.TenHangHoa,HN.Gia "+
                    "from dbo.PhieuDeNghiMuaHang_HangHoa PH, dbo.HangHoa_NhaCungCap HN, dbo.HangHoa H "+
                "where PH.MaPhieuDeNghiMuaHang='"+this.maPhieu+"' and HN.MaNhaCungCap='"+this.maNcc+"' and PH.HangHoa_NhaCungCap_ID = HN.HangHoa_NhaCungCap_ID and HN.MaHangHoa=H.MaHangHoa";
                
                SqlDataAdapter dataAdaptor = new SqlDataAdapter(sql, con);
                dataAdaptor.Fill(this, "DonDatHang");

                //DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable tb = new DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable();
                //DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter da = new DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter();

                //da.Fill(tb, ID);

            }

            public void viewReport()
            {

                _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
                _DB.PhieuDeNghiMuaHang P = dc.PhieuDeNghiMuaHangs.Single(s => s.MaPhieu == this.maPhieu);
                _DB.NhaCungCap N = dc.NhaCungCaps.Single(s => s.MaNhaCungCap == this.maNcc);




                trash.CR_DonDatHang report = new trash.CR_DonDatHang();
                report.SetDataSource(this);
                //report.SetParameterValue("MaPhieu", P.MaPhieu);
                report.SetParameterValue("MaNguoiTao", P.NguoiTao.Ten);
                report.SetParameterValue("NhaCC", N.TenNhaCungCap);
                ReportViewerForm form = new ReportViewerForm(report);
                form.ShowDialog();
            }
        
    }
}
